//
//  ByViewHomeIndexHeader.m
//  mijifen_ios
//
//  Created by 朱凯 on 2017/10/30.
//  Copyright © 2017年 itboye. All rights reserved.
//

#import "ByViewHomeIndexHeader.h"

@implementation ByViewHomeIndexHeader
{
    UIImageView *_bgView;           // 背景
    UIImageView *_scoreIconView;    // 积分图标
    UIImageView *_redPacketView;    // 红包
    
    UILabel     *_scoreLabel;       // 积分
    UILabel     *_signLabel;        // 签到（已签到显示“已签到”，和未签到显示“签到领积分”）
    UILabel     *_questionLabel;    // 问题
}

- (instancetype)initWithFrame:(CGRect)frame {
    
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = [UIColor redColor];
        [self setupUI];
    }
    return self;
}
- (void)setupUI {
    
    // 背景视图
    _bgView = [[UIImageView alloc] init];
    _bgView.image = [UIImage imageNamed:@"头视图背景"];
    [self addSubview:_bgView];
   
    // 积分
    _scoreLabel = [[UILabel alloc] init];
    _scoreLabel.text = @"200000";
    _scoreLabel.font = FONT(24);
    _scoreLabel.textColor = BY_GOLD_COLOR;
    [self addSubview:_scoreLabel];
  
    // 积分图标
    _scoreIconView = [[UIImageView alloc] init];
    _scoreIconView.backgroundColor = [UIColor redColor];
    [self addSubview:_scoreIconView];
    
    // 红包
    _redPacketView = [[UIImageView alloc] init];
    _redPacketView.backgroundColor = [UIColor redColor];
    [self addSubview:_redPacketView];

    // 签到
    _signLabel = [[UILabel alloc] init];
    _signLabel.userInteractionEnabled = true;
    _signLabel.backgroundColor = BY_GOLD_COLOR;
    _signLabel.text = @"签到领积分";
    _signLabel.font = FONT(15);
    _signLabel.textAlignment = NSTextAlignmentCenter;
    _signLabel.textColor = [UIColor whiteColor];
    _signLabel.layer.masksToBounds = true;
    _signLabel.layer.cornerRadius = 15;
    [self addSubview:_signLabel];
    
    // 问题
    _questionLabel = [[UILabel alloc] init];
    _questionLabel.userInteractionEnabled = true;
    _questionLabel.text = @"积分能干什么?";
    _questionLabel.font = FONT(14);
    _questionLabel.textColor = BY_GOLD_COLOR;
    [self addSubview:_questionLabel];
    NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:_questionLabel.text];
    [attr addAttribute:NSUnderlineStyleAttributeName value:@1 range:NSMakeRange(0, _questionLabel.text.length)];
    _questionLabel.attributedText = attr.copy;
    
    
    // 布局
    [_bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self).priorityMedium();
    }];
    [_scoreLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(@0);
        make.bottom.equalTo(_signLabel.mas_top).offset(-20);
    }];
    [_scoreIconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(25, 25));
        make.left.equalTo(_scoreLabel.mas_right).offset(5);
        make.centerY.equalTo(_scoreLabel);
    }];
    [_signLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(@-20);
        make.size.mas_equalTo(CGSizeMake(100, 30));
        make.centerX.equalTo(@0);
    }];
    [_redPacketView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(30, 40));
        make.centerY.equalTo(_signLabel);
        make.centerX.equalTo(_signLabel.mas_left).multipliedBy(0.5);
    }];
    [_questionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_signLabel.mas_right).offset(20);
        make.centerY.equalTo(_signLabel);
    }];
    
}


- (void)setOffset:(CGFloat)offset {
    
    _offset = offset;
    [self setNeedsUpdateConstraints];
}
- (void)updateConstraints {
    
    [_bgView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(self.offset);
    }];
    
    [super updateConstraints];
}



@end
